<?php
/**
 * Created by : PhpStorm
 * User: DuFei
 * Date: 2020/7/30
 * Time: 9:57
 */

namespace app\models;



class BaseDto implements \JsonSerializable
{

    /**
     * @return array
     */
    public function jsonSerialize()
    {
        return $this->toArray();
    }

    /**
     * @return array
     */
    public function toArray() {
        $arr = [];
        $r = new \ReflectionClass($this);
        $properties = $r->getProperties();

        foreach ($properties as $property) {
            $getMethod = "get".$property->getName();
            $arr[$property->getName()] = $this->{$getMethod}();
        }
        return $arr;
    }

}
